package com.cz.modules.cw.controller;

import java.util.*;

import com.cz.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cz.modules.cw.entity.CwParkingEntity;
import com.cz.modules.cw.service.CwParkingService;
import com.cz.common.utils.PageUtils;
import com.cz.common.utils.R;



/**
 * 停车场管理
 *
 * @author Cz
 * @email 
 * @date 2020-04-10 10:20:00
 */
@RestController
@RequestMapping("cw/cwparking")
public class CwParkingController {
    @Autowired
    private CwParkingService cwParkingService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("cw:cwparking:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = cwParkingService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{pkid}")
    @RequiresPermissions("cw:cwparking:info")
    public R info(@PathVariable("pkid") String pkid){
        CwParkingEntity cwParking = cwParkingService.getById(pkid);

        return R.ok().put("cwParking", cwParking);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("cw:cwparking:save")
    public R save(@RequestBody CwParkingEntity cwParking){
        cwParkingService.save(cwParking);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("cw:cwparking:update")
    public R update(@RequestBody CwParkingEntity cwParking){
        ValidatorUtils.validateEntity(cwParking);
        cwParkingService.updateById(cwParking);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("cw:cwparking:delete")
    public R delete(@RequestBody String[] pkids){
        cwParkingService.removeByIds(Arrays.asList(pkids));
        return R.ok();
    }
    //查询空余厕位
    @RequestMapping("/checkEmptycw")
    public R checkEmptycw(){
        List<Integer> list = cwParkingService.checkEmptycw();
        return R.ok().put("list", list);
    }

    //查询厕所温度等属性值
    @RequestMapping("/checkEnvironmentcw")
    public R checkEnvironmentcw(){
        Map<String,String> map = new HashMap<>();
        map = cwParkingService.checkEnvironmentcw();
        return R.ok().put("map", map);
    }

}
